package jee.boot.module.bpm.table.mysql;

import com.google.common.collect.Maps;
import jee.boot.common.CommonConstant;
import jee.boot.common.basic.result.MapData;
import jee.boot.entity.bpm.BpmConstant;

import java.util.Map;

/**
 * 审计字段创建工具
 */
public class AuditFieldUtils {
    public static Map<String, Object> createAuditField(String fieldName) {
        switch (fieldName) {
            case CommonConstant.AUDIT_FIELD_CREATE_BY:
                return createAuditField(fieldName, CommonConstant.AUDIT_COLUMN_CREATE_BY, "创建人", BpmConstant.BPM_COLUMN_DATA_TYPE_STRING, 64, 994);
            case CommonConstant.AUDIT_FIELD_CREATE_DATE:
                return createAuditField(fieldName, CommonConstant.AUDIT_COLUMN_CREATE_DATE, "创建时间", BpmConstant.BPM_COLUMN_DATA_TYPE_DATE, 0, 995);
            case CommonConstant.AUDIT_FIELD_UPDATE_BY:
                return createAuditField(fieldName, CommonConstant.AUDIT_COLUMN_UPDATE_BY, "修改人", BpmConstant.BPM_COLUMN_DATA_TYPE_STRING, 64, 996);
            case CommonConstant.AUDIT_FIELD_UPDATE_DATE:
                return createAuditField(fieldName, CommonConstant.AUDIT_COLUMN_UPDATE_DATE, "修改时间", BpmConstant.BPM_COLUMN_DATA_TYPE_DATE, 0, 997);
            case CommonConstant.AUDIT_FIELD_STATUS:
                return createAuditField(fieldName, CommonConstant.AUDIT_COLUMN_STATUS, "数据状态", BpmConstant.BPM_COLUMN_DATA_TYPE_STRING, 64, 998);
            case CommonConstant.AUDIT_FIELD_REMARKS:
                return createAuditField(fieldName, CommonConstant.AUDIT_COLUMN_REMARKS, "备注", BpmConstant.BPM_COLUMN_DATA_TYPE_STRING, 255, 999);
        }
        return null;
    }

    private static Map<String, Object> createAuditField(String fieldName, String columnName, String comment, String dataType, Integer length, int sort) {
        return MapData.instance()
                .put("fieldName", fieldName)
                .put("columnName", columnName)
                .put("comment", comment)
                .put("dataType", dataType)
                .put("length", length)
                .put("sort", sort)
                .put("auditField", BpmConstant.SYS_YES)
                .put("i18n", MapData.instance()
                        .put("code", "formdesigner.entity."+columnName)
                        .put("label", comment).data()
                ).data();
    }
}
